home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML Instance.sea / XML Instance / Required / plugins / HTMLWindow.jar / horst / TableCell.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-03-18  |  6.6 KB  |  271 lines

  1. package horst;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.Rectangle;
  6. import java.awt.Shape;
  7. import java.util.Hashtable;
  8.  
  9. public class TableCell extends View {
  10.    int m_rowSpan;
  11.    int m_colSpan;
  12.    int m_startColumn;
  13.    int m_endColumn;
  14.    int m_startRow;
  15.    int m_endRow;
  16.    int m_width;
  17.    int m_height;
  18.    Color m_bgColor;
  19.    int m_borderSize;
  20.    int m_valign;
  21.    TableRow m_row;
  22.    TableView m_tableView;
  23.    Rectangle m_cellBounds;
  24.  
  25.    public TableCell(View rowViewParent, TableView tableView, Element e, HTMLPane container) {
  26.       super(rowViewParent, e, container);
  27.       this.m_tableView = tableView;
  28.    }
  29.  
  30.    protected int checkWidthHeightAttributes(int axis, int span) {
  31.       if (axis == 1) {
  32.          if (this.m_width != -1 && this.m_width > span) {
  33.             span = this.m_width;
  34.          }
  35.       } else if (this.m_height != -1 && this.m_height > span) {
  36.          span = this.m_height;
  37.       }
  38.  
  39.       return span;
  40.    }
  41.  
  42.    protected int doCellVerticalAlignment(LayoutInfo info) {
  43.       int adjustment = 0;
  44.       Rectangle childrenBounds = super.getBounds();
  45.       if (this.m_cellBounds != null && childrenBounds != null) {
  46.          int cellPadding = this.m_tableView.m_cellPadding;
  47.          if (this.m_valign == 1) {
  48.             int availSpace = this.m_cellBounds.height - 2 * cellPadding - 2 * this.m_borderSize;
  49.             if (availSpace > childrenBounds.height) {
  50.                super.move(0, (availSpace - childrenBounds.height) / 2, true);
  51.             }
  52.          } else if (this.m_valign == 2) {
  53.             int availSpace = this.m_cellBounds.height - 2 * cellPadding - 2 * this.m_borderSize;
  54.             if (availSpace > childrenBounds.height) {
  55.                super.move(0, availSpace - childrenBounds.height, true);
  56.             }
  57.          }
  58.  
  59.          if (info.bPaginate) {
  60.             info.setPageBreak(this.m_cellBounds.y);
  61.             int origHeight = this.m_cellBounds.height;
  62.             super.pageBreakAdjust(info);
  63.             this.m_cellBounds.height = 2 * this.m_borderSize + 2 * this.m_tableView.m_cellPadding + super.m_bounds.height;
  64.             if (origHeight > this.m_cellBounds.height) {
  65.                this.increaseHeight(origHeight - this.m_cellBounds.height);
  66.             }
  67.  
  68.             adjustment = this.m_cellBounds.height - origHeight;
  69.          }
  70.       }
  71.  
  72.       return adjustment;
  73.    }
  74.  
  75.    public Rectangle getBounds() {
  76.       return this.m_cellBounds;
  77.    }
  78.  
  79.    protected int getMinimumSpan(int axis) {
  80.       if (axis == 1) {
  81.          if (super.m_minWidth != -1) {
  82.             return super.m_minWidth;
  83.          } else {
  84.             int paddingAndBorder = 2 * this.m_tableView.m_cellPadding + 2 * this.m_borderSize;
  85.             int var5 = paddingAndBorder + super.getMinimumSpan(1);
  86.             return var5;
  87.          }
  88.       } else if (super.m_minHeight != -1) {
  89.          return super.m_minHeight;
  90.       } else {
  91.          int paddingAndBorder = 2 * this.m_tableView.m_cellPadding + 2 * this.m_borderSize;
  92.          int m_minWidth;
  93.          if (this.m_height >= 0) {
  94.             m_minWidth = this.m_height;
  95.          } else {
  96.             m_minWidth = super.getMinimumSpan(axis);
  97.          }
  98.  
  99.          super.m_minHeight = m_minWidth;
  100.          return super.m_minHeight;
  101.       }
  102.    }
  103.  
  104.    protected int getPreferredSpan(int axis) {
  105.       if (axis == 1) {
  106.          if (super.m_prefWidth != -1) {
  107.             return super.m_prefWidth;
  108.          } else {
  109.             int paddingAndBorder = 2 * this.m_tableView.m_cellPadding + 2 * this.m_borderSize;
  110.             int var6 = paddingAndBorder + super.getPreferredSpan(1);
  111.             if (this.m_width != -1 && this.m_width > 0) {
  112.                if (this.m_width >= var6) {
  113.                   var6 = this.m_width;
  114.                } else {
  115.                   if (!super.m_bCanWrap) {
  116.                      ((View)this).setCanWrap(true);
  117.                   }
  118.  
  119.                   int minSpan = super.getMinimumSpan(1) + paddingAndBorder;
  120.                   if (minSpan <= this.m_width) {
  121.                      var6 = this.m_width;
  122.                   } else {
  123.                      var6 = minSpan;
  124.                   }
  125.                }
  126.             }
  127.  
  128.             super.m_prefWidth = var6;
  129.             return super.m_prefWidth;
  130.          }
  131.       } else if (super.m_prefHeight != -1) {
  132.          return super.m_prefHeight;
  133.       } else {
  134.          int paddingAndBorder = 2 * this.m_tableView.m_cellPadding + 2 * this.m_borderSize;
  135.          int span;
  136.          if (this.m_height >= 0) {
  137.             span = this.m_height;
  138.          } else {
  139.             span = super.getPreferredSpan(axis);
  140.          }
  141.  
  142.          super.m_prefHeight = span;
  143.          return super.m_prefHeight;
  144.       }
  145.    }
  146.  
  147.    protected void increaseHeight(int yIncrease) {
  148.       if (this.m_cellBounds != null) {
  149.          Rectangle var10000 = this.m_cellBounds;
  150.          var10000.height += yIncrease;
  151.       }
  152.  
  153.    }
  154.  
  155.    protected void init() {
  156.       this.m_row = (TableRow)super.m_parent;
  157.       this.m_cellBounds = new Rectangle();
  158.       Hashtable atts = super.m_elem.getAttributes();
  159.       this.m_width = Utilities.setIntegerProperty(-1, "width", atts);
  160.       this.m_height = Utilities.setIntegerProperty(-1, "height", atts);
  161.       this.m_bgColor = Utilities.setColorProperty(this.m_row.m_bgColor, "bgcolor", atts);
  162.       this.m_colSpan = Utilities.setIntegerProperty(1, "colspan", atts);
  163.       this.m_rowSpan = Utilities.setIntegerProperty(1, "rowspan", atts);
  164.       this.m_colSpan = Math.max(1, this.m_colSpan);
  165.       this.m_rowSpan = Math.max(1, this.m_rowSpan);
  166.       switch (super.m_elem.getType()) {
  167.          case 4:
  168.             super.m_alignment = 1;
  169.             break;
  170.          default:
  171.             super.m_alignment = Utilities.setAlignmentProperty(false, -1, "align", atts);
  172.             if (super.m_alignment == -1) {
  173.                super.m_alignment = this.m_row.m_alignment;
  174.             }
  175.       }
  176.  
  177.       this.m_valign = Utilities.setAlignmentProperty(true, -1, "valign", atts);
  178.       if (this.m_valign == -1) {
  179.          this.m_valign = this.m_row.m_valign;
  180.       }
  181.  
  182.    }
  183.  
  184.    protected boolean isFloaterClearer() {
  185.       return true;
  186.    }
  187.  
  188.    protected Rectangle layout(int x, int y, int width, LayoutInfo info) {
  189.       int xPos = x + this.m_tableView.m_cellPadding + this.m_borderSize;
  190.       int yPos = y + this.m_tableView.m_cellPadding + this.m_borderSize;
  191.       int space = width - 2 * this.m_tableView.m_cellPadding - 2 * this.m_borderSize;
  192.       space = Math.max(0, space);
  193.       boolean bPaginate = info.bPaginate;
  194.       Rectangle startPageBreak = new Rectangle(info.pageBreak);
  195.       info.bPaginate = false;
  196.       super.layout(xPos, yPos, space, info);
  197.       info.bPaginate = bPaginate;
  198.       info.pageBreak = startPageBreak;
  199.       this.m_cellBounds = new Rectangle(x, y, width, 0);
  200.       if (this.m_height != -1 && this.m_height - 2 * this.m_tableView.m_cellPadding > super.m_bounds.height) {
  201.          this.m_cellBounds.height = this.m_height + 2 * this.m_borderSize;
  202.       } else {
  203.          this.m_cellBounds.height = 2 * this.m_borderSize + 2 * this.m_tableView.m_cellPadding + super.m_bounds.height;
  204.       }
  205.  
  206.       return this.m_cellBounds;
  207.    }
  208.  
  209.    protected void makeChildren(ViewFactory factory) {
  210.       super.makeChildren(factory);
  211.       if (super.m_elem.isAttributeDefined("nowrap")) {
  212.          super.setCanWrap(false);
  213.       }
  214.  
  215.    }
  216.  
  217.    protected void move(int x, int y, boolean bMoveFloaters) {
  218.       if (this.m_cellBounds != null) {
  219.          super.move(x, y, bMoveFloaters);
  220.          Rectangle var10000 = this.m_cellBounds;
  221.          var10000.x += x;
  222.          var10000 = this.m_cellBounds;
  223.          var10000.y += y;
  224.       }
  225.  
  226.    }
  227.  
  228.    protected boolean occupies(int row, int col) {
  229.       return row >= this.m_startRow && row <= this.m_endRow && col >= this.m_startColumn && col <= this.m_endColumn;
  230.    }
  231.  
  232.    protected int pageBreakAdjust(LayoutInfo info) {
  233.       int adjustment = super.pageBreakAdjust(info);
  234.       this.m_cellBounds.height = 2 * this.m_borderSize + 2 * this.m_tableView.m_cellPadding + super.m_bounds.height;
  235.       return adjustment;
  236.    }
  237.  
  238.    public void paint(Graphics g, Shape alloc) {
  239.       Rectangle clip = alloc.getBounds();
  240.       if (this.m_cellBounds.intersects(clip)) {
  241.          if (this.m_bgColor != null) {
  242.             Color oldColor = g.getColor();
  243.             g.setColor(this.m_bgColor);
  244.             g.fillRect(this.m_cellBounds.x, this.m_cellBounds.y, this.m_cellBounds.width, this.m_cellBounds.height);
  245.             g.setColor(oldColor);
  246.          }
  247.  
  248.          super.paint(g, alloc);
  249.       }
  250.  
  251.    }
  252.  
  253.    protected void paintFocusBox(Graphics g, Shape alloc) {
  254.       Rectangle clip = alloc.getBounds();
  255.       if (this.m_cellBounds.intersects(clip)) {
  256.          super.paintFocusBox(g, alloc);
  257.       }
  258.  
  259.    }
  260.  
  261.    protected void setTableColumns(int start) {
  262.       this.m_startColumn = start;
  263.       this.m_endColumn = this.m_startColumn + this.m_colSpan - 1;
  264.    }
  265.  
  266.    protected void setTableRows(int start) {
  267.       this.m_startRow = start;
  268.       this.m_endRow = this.m_startRow + this.m_rowSpan - 1;
  269.    }
  270. }
  271.